<template>
    <el-container>
        <el-header style="height: 50px;border-bottom: none">
            <div class="left-panel">
				<div class="finish" style="margin: 0">
                    <div class="finishNum">剪数:<div class="text">{{ total_stock.cut_sum }}</div></div>
                    <div class="finishNum">来数:<div class="text">{{ total_stock.come_sum }}</div></div>
                    <div class="finishNum">码数:<div class="text">{{ total_stock.code_number_sum }}</div></div>
                    <div class="finishNum">米数:<div class="text">{{ total_stock.meter_sum }}</div></div>
                    <div class="finishNum">匹数:<div class="text">{{ total_stock.count }}</div></div>
                    <div class="finishNum">净重:<div class="text">{{ total_stock.net_weight_sum }}</div></div>
                </div>
            </div>
        </el-header>
        <el-header style="height: 50px;border-bottom: none">
            <div class="left-panel">
                <el-button type="primary" @click="output" v-auth="'new_inspect.print'">产量统计</el-button>
				<sc-export-button :auth="'new_inspect.export'" :apiObj="apiObj" :search="search" :selection="selection"></sc-export-button>
            </div>
            <div class="right-panel">
                <div class="right-panel-search">
                    <el-input v-model="search.test_code" placeholder="检验单号" clearable @keyup.enter="upsearch"></el-input>
                    <el-input v-model="search.purchase_ware_code" placeholder="入库单号" clearable @keyup.enter="upsearch"></el-input>
                    <el-input v-model="search.purchase_code" placeholder="采购单号" clearable @keyup.enter="upsearch"></el-input>
                    <el-select v-model="search.work_uid" placeholder="检验员" filterable clearable>
                        <el-option v-for="item in adminList" :key="item.id" :label="item.name" :value="item.id"></el-option>
                    </el-select>
                    <el-select style="margin:5px" v-model="search.ware_id" placeholder="仓库" filterable clearable>
                        <el-option v-for="item in wareList" :key="item.id" :label="item.ware_name" :value="item.id"></el-option>
                    </el-select>
                </div>
            </div>
        </el-header>
        <el-header>
            <div class="left-panel"></div>
            <div class="right-panel">
                <div class="right-panel-search">
                    <el-input v-model="search.search_keyword"  class="input-with-search" style="margin:5px;width: 300px" @keyup.enter="upsearch">
                        <template #prepend>
                            <el-select v-model="search.search_field" filterable clearable placeholder="请选择" style="width: 110px">
                                <el-option label="布卷条码" value="roll_code"/>
                                <el-option label="Color" value="color"/>
                                <el-option label="染色方" value="dye_factory_name"/>
                                <el-option label="加工方" value="process_factory_name"/>
                                <el-option label="批号" value="batch_num"/>
                            </el-select>
                        </template>
                    </el-input>
                    <sc-auto-complete style="margin:5px;width: 180px" v-model="search.goods_name" :api="$API.basic.goods.list" :params-key="'name'" :value-key="'name'" placeholder="品名" @select="getGoods"/>
                    <sc-auto-complete style="margin:5px;width: 180px" v-model="search.flower" :api="$API.basic.allFlower" :additionalParams="{type: 2}" :params-key="'flower'" :rows-key="'rows'" :value-key="'flower'" placeholder="花型" @select="getFlower"/>
                    <sc-auto-complete style="margin:5px;width: 180px" v-model="search.goods_code" :api="$API.basic.goods.list" :params-key="'code'" :rows-key="'rows'" :value-key="'code'" placeholder="货号" @select="getGoodsCode"/>
                    <sc-auto-complete style="margin:5px;width: 180px" v-model="search.apply_name" :api="$API.basic.apply.list" :params-key="'keyword'" :rows-key="'rows'" :value-key="'apply_name'" placeholder="供应商" @select="getApply"/>
                    <el-input style="margin:5px;width: 80px" v-model="search.gram_weight[0]" placeholder="克重" clearable @keyup.enter="upsearch"></el-input>
                    <span> - </span>
                    <el-input style="margin:5px;width: 80px" v-model="search.gram_weight[1]" placeholder="克重" clearable @keyup.enter="upsearch"></el-input>
                    <el-date-picker v-model="search.date" :value-format="'YYYY-MM-DD'" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" style="margin:5px;width: 220px" />
                    <!-- <el-input v-model="search.goods_code" placeholder="货号" clearable @keyup.enter="upsearch"></el-input> -->
                    <!-- <el-select v-model="search.ware_id" placeholder="检验员" filterable clearable>
                        <el-option v-for="item in wareList" :key="item.id" :label="item.ware_name" :value="item.id"></el-option>
                    </el-select>
                    <el-select v-model="search.ware_id" placeholder="折码" filterable clearable>
                        <el-option v-for="item in wareList" :key="item.id" :label="item.ware_name" :value="item.id"></el-option>
                    </el-select>
                    <el-date-picker v-model="search.date" :value-format="'YYYY-MM-DD'" type="daterange" range-separator="至" start-placeholder="开始日期" end-placeholder="结束日期" /> -->
                    <el-button type="primary" icon="el-icon-search" @click="upsearch"></el-button>
                    <el-button type="primary" icon="el-icon-refresh" @click="refresh"></el-button>
                </div>
            </div>
        </el-header>
        <el-main class="nopadding">
            <scTable ref="table" :apiObj="apiObj" row-key="id" @selection-change="selectionChange" border @setExtend="setExtend" :params="query" tableName="new_inspectTable" :column="inspectColumn">
                <el-table-column type="selection" width="50" align="center"></el-table-column>
                <template #index="scope">
                    {{ scope.$index + 1 }}
                </template>
                <!-- <el-table-column label="检验员" prop="" align="center"></el-table-column>
                <el-table-column label="日期" prop="" align="center"></el-table-column>
                <el-table-column label="折码" prop="" align="center"></el-table-column>
                <el-table-column label="货号" prop="" align="center"></el-table-column>
                <el-table-column label="批号" prop="" align="center"></el-table-column>
                <el-table-column label="品名" prop="" align="center"></el-table-column>
                <el-table-column label="Color" prop="" align="center"></el-table-column>
                <el-table-column label="花型" prop="" align="center"></el-table-column>
                <el-table-column label="匹数" prop="" align="center"></el-table-column>
                <el-table-column label="检验数量" prop="" align="center"></el-table-column>
                <el-table-column label="来数" prop="" align="center"></el-table-column>
                <el-table-column label="米数" prop="" align="center"></el-table-column>
                <el-table-column label="码数" prop="" align="center"></el-table-column>
                <el-table-column label="毛重" prop="" align="center"></el-table-column>
                <el-table-column label="净重" prop="" align="center"></el-table-column>
                <el-table-column label="克重" prop="" align="center"></el-table-column>
                <el-table-column label="类型" prop="" align="center"></el-table-column>
                <el-table-column label="消耗数量" prop="" align="center"></el-table-column>
                <el-table-column label="采购单号" prop="" align="center"></el-table-column>
                <el-table-column label="入库单号" prop="" align="center"></el-table-column>
                <el-table-column label="检验单号" prop="" align="center"></el-table-column> -->
            </scTable>
        </el-main>
        <select-house v-if="dialog.house" ref="houseDialog" @success="houseBack" @closed="dialog.house = false" :query="query"></select-house><!-- 入库记录 -->
        <print-save v-if="dialog.print" ref="printDialog" @success="printBack" @closed="dialog.print = false"></print-save>
    </el-container>
</template>

<script>
import SelectHouse from '@/views/business/selectHouse.vue';
import PrintSave from './printSave.vue';
export default {
    name: '已发货明细',
    components: {
        SelectHouse,
        PrintSave
    },
    data() {
        return {
            dialog: {
                house: false
            },
            apiObj: this.$API.ware.ware.summary.list,
            selection: [],
            search: {
                purchase_code: null,
                date: null,
                status: null,
                goods_name: null,
                gram_weight: [],
                is_old: 1
            },
            total_stock: {},
            query: {
                is_old: 1
            },
            wareList: [],
            adminList: [],
            inspectColumn: [
                {label: "序号", prop: "index", align: "center", width: "50", type: "index"},
                {label: "布卷条码", prop: "roll_code", align: "center", width: "150"},
                {label: "日期", prop: "action_date", align: "center", width: "150"},
                {label: "批号", prop: "batch_num", align: "center", width: "215"},
                {label: "品名", prop: "goods_name", align: "center", width: "150"},
                {label: "货号", prop: "goods_code", align: "center", width: "150"},
                {label: "花型", prop: "flower", align: "center", width: "150"},
                {label: "颜色", prop: "color", align: "center", width: "150"},
                {label: "Color", prop: "color_en", align: "center", width: "150"},
                {label: "来数", prop: "come", align: "center", width: "80"},
                {label: "剪数", prop: "cut", align: "center", width: "80"},
                {label: "米数", prop: "meter", align: "center", width: "80"},
                {label: "码数", prop: "code_number", align: "center", width: "80"},
                {label: "净重", prop: "net_weight", align: "center", width: "80"},
                {label: "克重", prop: "gram_weight", align: "center", width: "80"},
                {label: "检验数量", prop: "check_num", align: "center", width: "80"},
                {label: "仓库", prop: "ware.ware_name", align: "center", width: "150"},
                {label: "折码", prop: "folding", align: "center", width: "150"},
                {label: "次品种类", prop: "reject_cate", align: "center", width: "150"},
                {label: "检验员", prop: "work_uids_name", align: "center", width: "150"},
                {label: "供应商", prop: "apply_name", align: "center", width: "150"},
                {label: "染色方", prop: "dye_factory_name", align: "center", width: "150"},
                {label: "加工方", prop: "process_factory_name", align: "center", width: "126"},
                {label: "采购单号", prop: "purchase_code", align: "center", width: "150"},
                {label: "入库单号", prop: "purchaseware.purchase_ware_code", align: "center", width: "165"},
                {label: "检验单号", prop: "test.test_code", align: "center", width: "170"},
                // {label: "成本价", prop: "base_price", align: "center", width: "150",columbAuth: "inware.base_price"},
                // {label: "指导价", prop: "price", align: "center", width: "150",columbAuth: "inware.price"},
            ],
        }
    },
    mounted() {
		this.getWare();
		this.getAdmin();
    },
    methods: {
        setExtend(data){
            this.total_stock = data
        },
        upsearch(){
            this.$refs.table.upData(this.search)
        },
        refresh() {
            for (const key in this.search) {
                this.search[key] = null;
            }
            this.search.gram_weight = []
            this.search.is_old = 1
            this.$refs.table.upData(this.search)
        },
        // 仓库
		async getWare() {
			var res = await this.$API.basic.ware.all.get();
			this.wareList = res.data
		},
        // 管理员
		async getAdmin() {
			var res = await this.$API.system.admin.all.get();
			this.adminList = res.data
		},
        output(){
            this.dialog.print = true
            this.$nextTick(() => {
                this.$refs.printDialog.open('print')
            })
        },
        selectionChange(selection) {
			this.selection = selection;
		},

        getGoods(data){
            this.search.goods_name = data.name
            this.upsearch()
        },
        getGoodsCode(data){
            this.search.goods_code = data.code
            this.upsearch()
        },
        getApply(data){
            this.search.apply_name = data.apply_name
            this.upsearch()
        },
        getFlower(data){
            this.search.flower = data.flower
            this.upsearch()
        }
    }
}
</script>

<style lang="scss" scoped>
table{
    text-align: center ;
}
</style>
